package cn.fan.testfunction;

import cn.fan.testfunction.service.AmapClient;
import cn.fan.testfunction.service.Van;
import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.springboot.annotation.ForestScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.HashMap;
import java.util.Map;

/**
 * CommandLineRunner 在项目启动后执行run中方法
 * # 如果有多个类实现CommandLineRunner接口，如何保证顺序
 * > SpringBoot在项目启动后会遍历所有实现CommandLineRunner的实体类并执行run方法，如果需要按照一定的顺序去执行，那么就需要在实体类上使用一个@Order注解（或者实现Order接口）来表明顺序
 */
@EnableRetry
@EnableAsync
@SpringBootApplication
@ForestScan(basePackages = "cn.fan.testfunction.service")
public class TestFunctionApplication{// implements CommandLineRunner {
//    @Autowired
//    private Van van;

//    @Autowired
//    private AmapClient amapClient;

    public static void main(String[] args) {
        SpringApplication.run(TestFunctionApplication.class, args);
    }

//    @Override
//    public void run(String... args) throws Exception {
////        van.fight();
////        Map result = amapClient.getLocation("121.475078", "31.223577");
//        JSONObject login = amapClient.getLogin();
//        if (login != null) {
//            if ("OK".equals(login.get("Result").toString())) {
//                String ticket = ((JSONObject) login.get("Data")).get("Ticket").toString();
//////                JSONObject jsonObject = amapClient.addParam("test", "test", "test", "test", ticket);
//////                System.out.println(jsonObject);
//////
//////                if ("OK".equals(jsonObject.get("Result").toString())) {
//////                    Integer reId = (Integer) login.get("Data");
//////
//////                }
//                System.out.println(ticket);
//                JSONObject jsonObject = amapClient.listParam("2", "", ticket);
//                System.out.println(jsonObject);
//            }
//
//        }
//        HashMap<Object, Object> map = new HashMap<>();
//        map.put("Username","002");
//        map.put("Password","");
//        map.put("ForceRelogin",true);
//        JSONObject session = amapClient.getSession(map);
//
//        System.out.println(session);
//        HashMap<String, Object> map = new HashMap<>(2);
//        map.put("enterpriseId","100032");
//        map.put("username","18030527836");
//        String ticke= "Basic cm9vdDpodGhsQDIwMTg=";
//        JSONObject token = amapClient.getToken(map, ticke);
//        System.out.println(token);
//    }
}
